package interview.mergesortedstring;

public class MergeSortedString {
	public String run(char[] A, int lenA, char[] B) {
		int index = lenA + B.length - 1;
		int indexA = lenA - 1;
		int indexB = B.length - 1;
		while(indexA >= 0 && indexB >=0) {
			if(A[indexA] > B[indexB]) {
				A[index] = A[indexA];
				indexA--;
			} else {
				A[index] = B[indexB];
				indexB--;
			}
			index--;
		}
		
		while(indexB >= 0) {
			A[index] = B[indexB];
			indexB--;
			index--;
		}
		
		return new String(A, 0, lenA + B.length);
	}
}
